<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>装箱单明细</title>
    <style type="text/css">
        table tr {
            text-align: left;
            font-size: 13px;
            padding: 3px 0px;
        }

        .table_list_name {
            text-align: right
        }

        .packinglist {
            font-size: 18px;
            font-weight: bold;
            padding: 5px 0px;
        }

        .table-border tr td, .table-border tr th {
            border: 1px solid #000;
        }

        .table-border tr th {
            text-align: center;
        }

        .table-margin {
            margin-top: 10px
        }

        .tr_line {
            line-height: 25px;
        }

        .table_txt tr td {
            width: 10%
        }

        .hover {
            background-color: #cccc00;
        }
    </style>
    <jsp:include page="../../head.jsp"/>
</head>
<script type="text/javascript">
    $(document).ready(function () {
        $("#goodsPackingList tr:gt(0)").click(function () {
            $("#goodsPackingList tr").removeClass("hover");
            $(this).addClass("hover");
            $("#commodity_id").val($(this).find("td").eq(0).html());
            $("#id").val($(this).find("td").eq(1).html());
            $("#name").val($(this).find("td").eq(2).html());
            $("#key_elements").val($(this).find("td").eq(3).html());
            $("#goods_number").val($(this).find("td").eq(4).html());
            $("#count").val($(this).find("td").eq(5).html());
            $("#goods_gross_weight").val($(this).find("td").eq(6).html());
            $("#goods_net_weight").val($(this).find("td").eq(7).html());
            $("#goods_package").val($(this).find("td").eq(8).html());
            $("#packinglist_remark").val($(this).find("td").eq(9).html());
        });
    });

    var delFlag = false;
    function del(id) {
        if (!delFlag) {
            delFlag = true;
            $.ajax({
                       type: 'POST',
                       url: 'business-delPackingListDetailed',
                       data: {
                           'id': id
                       },
                       success: function (data, textStatus, jqXHR) {
                           var msg = $.parseJSON(data.msg);
                           alert(msg.msg);
                           if (msg.state == "1") {
                               location.reload();
                           }
                           delFlag = false;
                       },
                       dataType: 'json'
                   });
        }
    }
</script>
<script type="text/javascript">
    var state_option = [["启用", "0"], ["未启用", "1"]];
    var formSetting = {
        title: '装箱单明细',
        module: 'save',
        columns: [{
            id: "commodity_id",
            name: "commodity.id",
            hidden: true,
            value: "${param.commodity_id}"
        }, {
            id: "id",
            name: "id",
            hidden: true
        }, {
            id: "name",
            name: "name",
            label: "商品名称",
            validate: 'validate[required]'
        }, {
            id: "key_elements",
            name: "key_elements",
            label: "规格型号"
        }, {
            id: "goods_number",
            name: "goods_number",
            label: "件数"
        }, {
            id: "count",
            name: "count",
            label: "成交数量"
        }, {
            id: "goods_gross_weight",
            name: "goods_gross_weight",
            label: "毛重G.W."
        }, {
            id: "goods_net_weight",
            name: "goods_net_weight",
            label: "净重N.W."
        }, {
            id: "goods_package",
            name: "goods_package",
            label: "包装种类"
        }, {
            id: "packinglist_remark",
            name: "packinglist_remark",
            label: "备注"
        } /* , {
         name : "systemValue.use_state",
         value : "0",
         label : "使用状态",
         type : "dropdown",
         data : state_option,
         dropdownValue : "启用"
         } */],
        form: {
            'url': 'business-savePackingListDetailed',
            'data': function () {
            },
            'afterAjaxSuccess': function (responseText, statusText, xhr, $form) {
                if (responseText.result) {
                    location.reload();
                }
            }
        },
        buttons: {
            'custom': [
                {
                    id: "btnNew",
                    value: "新增",
                    click: function (event) {
                        $(event.srcElement).parents("form").find(
                                ":text,:hidden").val("");
                        $("#commodity_id").val("${commodity_id}");
                    }
                }, {
                    id: "btnConfirm",
                    value: "确定",
                    click: function (event) {
                        var total_goods_number = 0;
                        $("#goodsPackingList tr:gt(0)").each(function () {
                            total_goods_number += parseInt($(this).find("td").eq(4).text());
                        });
                        if (total_goods_number != "${param.goods_number}") {
                            alert("箱数/件数不一致！");
                        } else {
                            window.close();
                        }
                    }
                }]
        }
    };
    $(document).ready(function () {
        $("#formtable").mrdForm(formSetting);
    });
</script>
</head>
<body>
<div style="width: 100%">
    <div id="formtable"></div>
</div>
<table id="goodsPackingList" style="width: 100%"
       class="ui-jqgrid ui-widget ui-widget-content ui-corner-all tr_line table-margin">
    <tr class="ui-jqgrid-labels">
        <th class="ui-state-default ui-th-column ui-th-ltr"
            style="display: none;">commodity_id
        </th>
        <th class="ui-state-default ui-th-column ui-th-ltr"
            style="display: none;">id
        </th>
        <th class="ui-state-default ui-th-column ui-th-ltr">商品名称</th>
        <th class="ui-state-default ui-th-column ui-th-ltr">规格</th>
        <th class="ui-state-default ui-th-column ui-th-ltr">件数</th>
        <th class="ui-state-default ui-th-column ui-th-ltr">成交数量</th>
        <th class="ui-state-default ui-th-column ui-th-ltr">毛重G.W.</th>
        <th class="ui-state-default ui-th-column ui-th-ltr">净重N.W.</th>
        <th class="ui-state-default ui-th-column ui-th-ltr">包装种类</th>
        <th class="ui-state-default ui-th-column ui-th-ltr">备注</th>
        <th class="ui-state-default ui-th-column ui-th-ltr">操作</th>
    </tr>
    <c:forEach items="${packingListDetaileds}" var="st">
        <tr class="jqgrow ui-row-ltr">
            <td style="display: none;">${st.commodity.id}</td>
            <td style="display: none;">${st.id}</td>
            <td>${st.name}</td>
            <td>${st.key_elements}</td>
            <td>${st.goods_number}</td>
            <td>${st.count}</td>
            <td>${st.goods_gross_weight}</td>
            <td>${st.goods_net_weight}</td>
            <td>${st.goods_package}</td>
            <td>${st.packinglist_remark}</td>
            <td><a name="deleteBtn"
                   class="ui-button ui-widget ui-state-default ui-corner-all"
                   href="javascript:;" onclick="del('${st.id}');">删除</a></td>
        </tr>
    </c:forEach>
    <!-- <tr class="ui-widget-content jqgrow ui-row-ltr">
        <td colspan="2" align="right" style="text-align: right;">合计:</td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
    </tr> -->
</table>
</body>
</html>
